package com.csd.service.impl;/*
 * Description:
 * User:Hello，Mr.Zhou
 * Date:2020-12-22
 * Time:17:44
 *
 * */

import com.csd.dao.UserDao;
import com.csd.pojo.SysUser;
import com.csd.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired(required = false)
    private UserDao userDao;
    /*
    * 添加用户
    * */
    @Override
    public int register(SysUser user) {

        String tel = user.getTel();
        SysUser userByTel = userDao.findUserByTel(tel);
        if(userByTel == null ) {
            int i = userDao.addUser(user);
            System.out.println(i);
            return i;
        }
        return 0;
    }
    /*
    * 登录用户
    * */
    @Override
    public SysUser login(String tel, String password) {
        SysUser users = userDao.findUserByTelAndPassword(tel,password);
        if (!users.getTel().equals(tel)) {
            throw new RuntimeException("用户不存在");
        }
        if (!users.getPassword().equals(password)) {
            throw new RuntimeException("密码错误");
        }
        return users;
    }

    @Override
    public SysUser findUserById(int id) {
        return userDao.finduserById(id);
    }

    @Override
    public int updateUser(SysUser sysUser) {
        return 0;
    }

   /* @Override
    public SysUser ajaxRegister(String tel) {
        return userDao.findUserByTel(tel);
    }*/
}
